#include <stdlib.h>
#include <stdio.h>
#include "Vertex.h"
#include "GL/glut.h"
#include "include.h"

Vertex::Vertex()
{
	position = Vector2D(0,0);
	drawingMode = NORMAL_MODE;
	activeSegment = false;
}
Vertex::Vertex(Vector2D position)
{
	this->position = position;
	drawingMode = NORMAL_MODE;	
	activeSegment = false;
}

Vertex::Vertex(float x, float y)
{
	position = Vector2D(x, y);
	activeSegment = false;
}
Vertex::~Vertex()
{
}
void Vertex::Draw()
{
	//glPushMatrix();
	//glLoadIdentity();
	
	float size = 0.1;
	if(drawingMode == HOVER_MODE)
	{
		size = 0.7;
		glColor3f(1,1,1);
	}
	else
	{
		glColor3f(0.6,0.6,0.6);
	}
		
	
	glBegin(GL_QUADS);
	/*glVertex2f(position.x - size, position.y + size);
	glVertex2f(position.x + size, position.y + size);
	glVertex2f(position.x + size, position.y - size);
	glVertex2f(position.x - size, position.y - size);*/
	glVertex2f(-size,  size);
	glVertex2f( size,  size);
	glVertex2f( size, -size);
	glVertex2f(-size, -size);
	glEnd();
	
	//glPopMatrix();
}
void Vertex::HoverCheck(Mouse * mouse)
{
	if((position | mouse->GetPosition()) > 1)
	{
		drawingMode = NORMAL_MODE;
	}
	else
	{
		drawingMode = HOVER_MODE;
	}	
}
void Vertex::SetPosition(Vector2D position)
{
	this->position = position;
}
Vector2D Vertex::GetPosition()
{
	return position;
}
char * Vertex::GetRelativeTag(Vector2D relativePosition)
{
	char * tag = (char *)malloc(sizeof(char)*64);
	sprintf(tag, "(%f, %f)", position.x - relativePosition.x, position.y-relativePosition.y);	
	return tag;
}
char * Vertex::GetTag()
{
	char * tag = (char *)malloc(sizeof(char)*64);
	sprintf(tag, "(%f, %f)", position.x, position.y);	
	return tag;
}
